<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 16/4/5
 * Time: 下午6:40
 */
class RoleController extends AdminBaseController {

    public function lists(){
        $this->setTitle('角色列表');

        $filter = new PubFilter();
        $grid   = new PubGrid();

        $onlineOptions = array(
            ''  => '全部',
            '1' => '在线',
        );

        $filter->addOssServer()
            ->addFilter('role_name', 'input', '角色名')
            ->addFilter('role_id', 'input', '角色ID')
            ->addFilter('account_name', 'input', '平台账号')
            ->addFilter('is_online', 'radio', ' ', array('options' => $onlineOptions));

        $params = $filter->get();

        if(PubFunc::isAjax()){
            $this->out = RoleService::indexData($params);
            $this->outType = 'json';
        }else{
            $header = RoleService::indexHeader();

            $url = PubFunc::ajaxUrl('/oss/?r=role/lists', $params);

            $grid->addGrid($header, $url, array(
                'length' => 10
            ));

            $this->out['filter'] = $filter->show();
            $this->out['grid'] = $grid->show();
        }

    }

    public function index(){
        $this->setTitle('角色信息查询');

        $server = $this->R('server');
        $search = $this->R('search');

        $platform = PubBase::getCurrentPlatform();
        $game = PubBase::getCurrentGame();
        $serverList = ServerService::getOptions($platform, $game);
        if(empty($server)){
            $server = key($serverList);
        }

        $this->out['serverList'] = $serverList;

        if(!empty($search)){
            $this->out['server'] = $server;
            $this->out['search'] = $search;
            $this->out['role'] = RoleService::getInfo($server, $search);
            $this->out['extra_url'] = PubFunc::buildUrl('/oss/?r=role/extra');
        }
    }

    public function extra(){
        $roleId = $this->R('role');
        $type = $this->R('type');
        $server = $this->R('server');

        $this->out = RoleService::getExtra($server, $roleId, $type);
        $this->outType = 'json';
    }

}